//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELASTOS_TINTERRUPTDIRVER_H__
#define __ELASTOS_TINTERRUPTDIRVER_H__

#define MAX_ISR_NUM 20

typedef enum isr_func_No
{
    ISR_NULL            = 0,
    KbdNormalIsr        = 1,
    KbdIsr01            = 2,
    KbdIsr02            = 3,
    KbdIsr03            = 4,
    KbdIsr04            = 5,
    SerialIsr01         = 6,
    SerialIsr02         = 7,
    SerialIsr03         = 8,
    SerialIsr04         = 9,
    CommonIsr1          = 10,
    CommonIsr2          = 11,
    SerialIsrPrint      = 12,
    KbdIsrPrint         = 13,
    KbdIsrNotify0       = 14,
    SerialIsrNotify1    = 15,
    KbdIsrNotifyClear   = 16,
    SerialIsrNotifyClear= 17,
} isr_func_No;

typedef struct _TInterruptInfo
{
    uint8_t           irq;
    uint8_t           uIplNo;
    isr_func_No       IsrNo;
} TInterruptInfo, *PTInterruptInfo;

//
//
//
class TInterrupt : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ UInt64 u64Offset,
        /* [in] */ UInt32 bytesToRead,
        /* [out] */ EzByteBuf buffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ UInt64 u64Offset,
        /* [in] */ EzByteBuf buffer,
        /* [out] */ UInt32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ EzByteBuf inBuffer,
        /* [out] */ EzByteBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose() {}

    virtual ~TInterrupt();

    void TRegisterIsr(PTInterruptInfo pTInterruptInfo);

    ECode Initialize();

    uint8_t FindIplNo(ipl_t ipl);
    void RunThread();

public:
    IDeviceDriver         *m_pKbdDriver;
    IDeviceDriver         *m_pTSerialDriver1;
    IDeviceDriver         *m_pTSerialDriver2;
    DzEvent           *m_pEvent;

    isr_t   m_isrArray[MAX_ISR_NUM];
    ipl_t   m_iplArray[33];
};

#endif  // __ELASTOS_TINTERRUPTDIRVER_H__
